home *** CD-ROM | disk | FTP | other *** search
/ Tech Arsenal 1 / Tech Arsenal (Arsenal Computer).ISO / tek-01 / strlib.zip / MEMCMP.C < prev    next >
Text File  |  1993-01-04  |  1KB  |  35 lines

  1.  
  2. /*  File   : memcmp.c
  3.     Author : Richard A. O'Keefe.
  4.     Updated: 25 May 1984
  5.     Defines: memcmp()
  6.  
  7.     memcmp(lhs, rhs, len)
  8.     compares the two memory areas lhs[0..len-1]  ??  rhs[0..len-1].   It
  9.     returns  an integer less than, equal to, or greater than 0 according
  10.     as lhs[-] is lexicographically less than, equal to, or greater  than
  11.     rhs[-].  Note  that this is not at all the same as bcmp, which tells
  12.     you *where* the difference is but not what.
  13.  
  14.     Note:  suppose we have int x, y;  then memcmp(&x, &y, sizeof x) need
  15.     not bear any relation to x-y.  This is because byte order is machine
  16.     dependent, and also, some machines have integer representations that
  17.     are shorter than a machine word and two equal  integers  might  have
  18.     different  values  in the spare bits.  On a ones complement machine,
  19.     -0 == 0, but the bit patterns are different.
  20.  
  21.     This could have a Vax assembly code version, but as the return value
  22.     is not the value left behind by  the  cmpc3  instruction  I  haven't
  23.     bothered.
  24. */
  25.  
  26. int memcmp(lhs, rhs, len)
  27.     register char *lhs, *rhs;
  28.     register int len;
  29.     {
  30.         while (--len >= 0)
  31.             if (*lhs++ != *rhs++) return lhs[-1]-rhs[-1];
  32.         return 0;
  33.     }
  34.  
  35.